<?php
allowCors();
if (!methodsRequired(['post'])) return;
if (!checkAdmin($msg)) return;

$user = new User();
//必选参数
foreach (User::$required as $item){
    if(isset($_REQUEST[$item])){
        DbTable::callSetMethod($user,$item,$_REQUEST[$item]);
    }else{
        $msg->setCode(1);
        $msg->msg.= ",缺少 $item";
        echo $msg;
        return;
    }
}
//可选参数
foreach (array_diff(User::$members_mapping ,User::$required ) as $item){
    if(isset($_REQUEST[$item])&&$item!='user_id'){
        DbTable::callSetMethod($user,$item,$_REQUEST[$item]);
    }
}
error_log($user);
if(!$db->add($user)){
    $msg->setCode(1);
}
echo $msg;



